<template>
  <a-modal v-model="visible" :width="1180" title="选择活动商品库">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商品标题">
              <a-input placeholder="请输入商品标题" v-model="queryParam.title"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商品货号">
              <a-input placeholder="请输入商品货号" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="活动类型">
              <j-dict-select-tag v-model="queryParam.itemType" dictCode="market_type" :triggerChange="true" @change="searchQuery" />
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" @click="openUrlView(text)" height="80px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>

        <template slot="libStockSlot" slot-scope="text, record">
          <div v-if="record.itemType==2">{{record.msStock}}</div>
          <div v-if="record.itemType==3">{{record.ptStock}}</div>
          <div v-if="record.itemType==5">{{record.yyStock}}</div>
        </template>

        <template slot="activeStatus" slot-scope="text, record">
          <div v-if="record.activeStatus==0">下架中</div>
          <div v-if="record.activeStatus==1">正常</div>
          <div v-if="record.activeStatus==2">活动中</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-if="selectionType=='radio'&&record.activeStatus==1" @click="selectItem(record)">选择</a>
        </span>

      </a-table>
    </div>

  </a-modal>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/MyJeecgListMixin'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'

export default {
  name: 'GmsGoodLibList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDictSelectTag,
  },
  data () {
    return {
      pageCheckedKeys: [],
      noPageCheckedKeys: [],
      pageCheckedRows: [],
      noPageCheckedRows: [],
      visible: false,
      description: '活动商品库管理页面',
      // 表头
      columns: [
        {
          title: '商品货号',
          align: "left",
          dataIndex: 'code'
        },
        {
          title: '商品名称',
          align: "left",
          dataIndex: 'title'
        },
        {
          title: '图片',
          align: "center",
          dataIndex: 'imgUrl',
          scopedSlots: { customRender: "imgSlot" }
        },
        {
          title: '商品类型',
          align: "center",
          dataIndex: 'itemType_dictText'
        },
        {
          title: '活动库存',
          align: "right",
          dataIndex: 'yyStock',
          scopedSlots: { customRender: "libStockSlot" }
        },
        {
          title: '活动状态',
          align: "right",
          dataIndex: 'activeStatus',
          scopedSlots: { customRender: 'activeStatus' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/mallPlus/gmsGoodLib/list",
        delete: "/mallPlus/gmsGoodLib/delete",
        deleteBatch: "/mallPlus/gmsGoodLib/deleteBatch",
        exportXlsUrl: "/mallPlus/gmsGoodLib/exportXls",
        importExcelUrl: "mallPlus/gmsGoodLib/importExcel",

      },
      dictOptions: {},
    }
  },
  created () {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    open (itemType) {
      if (itemType) {
        this.queryParam['itemType'] = itemType
      }
      this.loadData()
    },
    searchReset () {
      this.queryParam = {
        itemType: this.queryParam.itemType
      }
      this.loadData(1)
    },
    setSelected () {
      this.pageCheckedKeys = []
      this.noPageCheckedKeys = []
      this.pageCheckedRows = []
      this.noPageCheckedRows = []
      for (let i = 0; i < this.checkedKeys.length; i++) {
        let isSelect = false
        for (let j = 0; j < this.dataSource.length; j++) {
          if (this.dataSource[j].id == this.checkedKeys[i]) {
            isSelect = true
          }
        }
        if (isSelect) {
          this.pageCheckedKeys.push(this.checkedKeys[i])
          this.pageCheckedRows.push(this.checkedRows[i])
        } else {
          this.noPageCheckedKeys.push(this.checkedKeys[i])
          this.noPageCheckedRows.push(this.checkedRows[i])
        }
      }
      this.selectedRowKeys = this.pageCheckedKeys
    },
    initDictConfig () {
    }
  }
}
        </script>
<style scoped>
@import '~@assets/less/common.less';
</style>
